<template>
	<view class="content" v-cloak>
			<!-- 公共部分 star-->
			<!-- 头部 star-->
			<view class="header_view p-r">
				<view class="header_bg_view p-a">
					<image class="header_bg p-a" :src="imgPrefix('/static/image/teacher/index_header.png')"></image>
					<image class="header_wave p-a" :src="imgPrefix('/static/image/teacher/wave.gif')"></image>
				</view>
				<view class="header_item c-f dis-flex flex-dir-column flex-x-end p-r">
					<view class="welcome_content p-a" :style="{ top: navTop }">
						<view class="welcome_top dis-flex flex-y-center">
							<block v-if="userIdentity==0">
								<image class="welcome_logo oh" :src="user.avatar != '' && user.avatar != undefined?user.avatar:imgPrefix('/static/image/icon/default_avatar.png')"></image>
								<text v-if="user.nickname != '' && user.nickname != undefined" class="user_name">{{ user.nickname }}</text>
								<view v-else class="user_name" @tap.stop="isLogin">未登录</view>
							</block>
							<block v-else-if="userIdentity==1">
								<image class="welcome_logo oh" :src="teacher.info.headeravatar != '' && teacher.info.headeravatar != undefined?teacher.info.headeravatar:imgPrefix('/static/image/icon/default_avatar.png')"></image>
								<text v-if="teacher.info.nickname != '' && teacher.info.nickname != undefined" class="user_name">{{ teacher.info.nickname }}</text>
								<view v-else class="user_name">未登录</view>
							</block>
						</view>
						<view class="welcome_bottom c-f f_48 f_6">Hi！可语星人</view>
						<!-- <view class="welcome_bottom c-f f_48 f_6">{{userIdentity == 0?'HI,欢迎使用可语':'Holle,可语星球'}}</view> -->
					</view>
					<view class="course_content" @tap.stop="bindHourView">
						<text class="course_title dis_b f_24">{{userIdentity == 0?'上':'授'}}课总时长</text>
						<text class="course_num c-f font_bebas">{{ (userIdentity == 0?hour_count:teacher.info.hour) || 0 }}</text>
						<text class="course_text f_22">小时</text>
					</view>
					<view class="address_search dis-flex flex-x-between flex-y-center p-a">
						<view class="dis-flex flex-y-center flex-box" @tap="latitude != '' ? pageTo('/pages/location_list/index', {}, '') : _getLocation()">
							<image class="address_cion" :src="imgPrefix('/static/image/icon/address.png')"></image>
							<view class="ctiy_name f_32 onelist-hidden f_semibold">{{ recommend }}</view>
							<image class="bottom_cion" :src="imgPrefix('/static/image/icon/bottom.png')"></image>
						</view>
						<image @tap.stop="pageTo('/pages/search_input/index')" class="search_icon" :src="imgPrefix('/static/image/icon/search.png')"></image>
					</view>
				</view>
			</view>
			<!-- 头部 end-->
			<!-- banner_swiper star-->
			<view class="banner_swiper">
				<swiper class="swiper_view" :autoplay="currentIndex==0" :previous-margin="bannerIndex == 0 ? '48rpx' : bannerIndex == bannerList.length - 1 ? '126rpx' : '48rpx'" :next-margin="bannerIndex == 0 ? '126rpx' : bannerIndex == bannerList.length - 1 ? '48rpx' : '126rpx'" :current="bannerIndex" @change="bannerSwiperChange"
				>
					<block v-for="(item, index) in bannerList" :key="index">
						<swiper-item class="swiper_item_view">
							<image mode="aspectFill" class="banner_img b32 oh" :class="bannerIndex != index && 'scale'" lazy-load :src="item.image" @click.stop="toBannerRouter(index, item.url)"
							></image>
						</swiper-item>
					</block>
				</swiper>
				<view class="current_items dis-flex">
					<view class="current_item" :class="bannerIndex == index && 'active'" v-for="(item, index) in bannerList" :key="index" @tap.stop="bindCurrentItem(index)"></view>
				</view>
			</view>
			<!-- banner_swiper end-->
			<!-- 公共部分 end-->
			
			<!-- 学生端 star-->
			<block v-if="userIdentity == 0">
				<!-- 语种分类 end-->
				<view class="language_classification">
					<view class="module_top_title language_title margin_view">
						<text class="module_title f_6 language_text">语种分类</text>
						<view class="scroll_icon p-r oh"><text class="scroll_icon_view p-a" :style="{ left: Math.abs(languageTypeScrollPortion * languageTypeScrollLeft) + 'rpx' }"></text></view>
					</view>
					<scroll-view scroll-x class="language_scroll" @scroll="languageTypeScroll" style="height:400rpx">
						<view class="language_scroll_view margin_view">
							<image lazy-load v-for="(item, index) in languageList" :key="index" :src="item.image" mode="aspectFill" class="language_img" @tap="bindClassification(index)" ></image>
						</view>
					</scroll-view>
				</view>
				<!-- 语种分类 end-->
				<!-- 可语分享 star-->
				<view class="speak_share" v-if="speakShareList.length>0">
					<view class="module_top_title margin_view">
						<text class="module_title f_6 share_text">可语资讯</text>
						<view class="get_more" @tap.stop="pageTo('/pages/article_list/index')">
							<text class="get_more_text">更多</text>
							<image class="get_more_icon" :src="imgPrefix('/static/image/icon/next.png')"></image>
						</view>
					</view>
					<swiper class="speak_share_swiper_view" :autoplay="currentIndex==0" circular>
						<block v-for="(item, index) in speakShareList" :key="index">
							<swiper-item class="speak_share_swiper_item" @tap.stop="pageTo('/pages/article_details/index', { id: item.article_id })">
								<image mode="aspectFill" class="speak_share_banner_img b32 oh" lazy-load :src="item.image"></image>
								<view class="share_content dis-flex flex-dir-column">
									<text class="share_title navy_blue f_5 f_28">{{ item.title }}</text>
									<text class="share_time f_24">{{ setTime(item.createtime) }}</text>
								</view>
							</swiper-item>
						</block>
					</swiper>
				</view>
				<!-- 可语分享 end-->
				<!-- 可语优选 star -->
				<view class="speak_select" v-if="selectList.length>0">
					<view class="module_top_title margin_view"><text class="module_title f_6 select_text">可语优选</text></view>
					<view class="select_title_bottom gery1 f_24 margin_view">可语通过数据综合统计，给你推荐专业老师</view>
					<course-list :selectList="selectList" :lat="latitude" :lon="longitude" @bind-index="toTeacherDetail"></course-list>
				</view>
				<!-- 可语优选 end-->
				<zan-popup :show="showBalanceLow" @close="closeBalanceLowPopup">
					<view class="popup">
						<image lazy-load class="search_img" :src="imgPrefix('/static/image/search.png')"></image>
						<view class="btn_view p-a" @tap="toQuestionnaire"></view>
						<image @tap.stop="closeBalanceLowPopup" class="close_border_icon" :src="imgPrefix('/static/image/icon/close_border_icon.png')"></image>
					</view>
				</zan-popup>
			</block>
			<!-- 学生端end -->
			<!-- 教师端star -->
			<block v-else-if="userIdentity == 1">
				<!-- 授课按钮satr -->
				<view class="teaching_status dis-flex flex-x-between flex-dir-column m_l_48 m_r_48">
					<view class="view_top dis-flex flex-x-between flex-y-center">
						<text class="f_semibold">开始授课</text>
						<view class="dis-flex flex-y-center" @tap.stop="pageTo('/pages/teacher/teaching_information/index')" >
							<text class="gery1">授课信息</text>
							<image lazy-load class="next_icon" :src="imgPrefix('/static/image/teacher/next_icon_gery.png')"></image>
						</view>
					</view>
					<view class="teaching_info dis-flex flex-x-between">
						
						<view class="info_view flex-box" v-if="teacher.info.teacher_course==null">
							<text class="f_28 navy_blue">授课信息暂未填写，填写后可开始接单。</text>
							<view class="to_write"  @tap.stop="pageTo('/pages/teacher/teaching_information/index')">
								<text class="violet1 f_28">去填写</text>
								<image class="image" lazy-load :src="imgPrefix('/static/image/icon/address_next.png')"></image>
							</view>
						</view>
						<block v-else>
							<block v-if="teacher.info.verify!=0">
								<view class="info_view">
									<text class="f_24 gery1">积累订单</text>
									<text class="f_40 navy_blue">{{teacher.info.order_count||0}}</text>
								</view>
								<view class="info_view">
									<text class="f_24 gery1">已上课次</text>
									<text class="f_40 navy_blue">{{teacher.info.course_count||0}}</text>
								</view>
								<view class="info_view">
									<text class="f_24 gery1">已上课时</text>
									<text class="f_40 navy_blue">{{teacher.info.hour||0}}</text>
								</view>
							</block>
						</block>
					</view>
					<!-- verify:身份认证状态 0=拒绝，1=审核中，2=通过  -->
					<!-- online：开课状态 1开课 0未开课 -->
					<view @tap.stop="bindOnline" :class="['btn',teacher.info.teacher_course==null?'no_teacher_course':teacher.info.verify != 2 ? 'write' : '', teacher.info.online != 1 ? 'open' : 'close']">
						{{ teacher.info.online ==1 ? '关闭' : '开启' }}接单
					</view>
				</view>
				<!-- 授课按钮end -->
				<!-- 公告 star -->
				<view class="notice_view dis-flex flex-x-center flex-y-center m_l_48 m_r_48" @tap.stop="pageTo('/pages/teacher/announcement_list/index')">
					<image class="image" :src="imgPrefix('/static/image/teacher/notice_img.png')"></image>
					<swiper class="swiper_view" circular :display-multiple-items="2" :vertical="true" :autoplay="true" :interval="3000" :duration="5000">
						<swiper-item class="swiper-item" v-for="(item,index) in teacher.newNoticeList" :key="index">
							<view class="swiper-item onelist-hidden">
								<text class="text"><text class="violet1">【{{getNoticeTitle(item.title,0)}}】</text>{{getNoticeTitle(item.title,1)}}</text>
							</view>
						</swiper-item>
					</swiper>
				</view>
				<!-- 公告 end -->
				<!--可语资讯 star -->
				<view class="learning_information">
					<view class="module_top_title margin_view"><text class="module_title f_6 learning_text">可语资讯</text>
						<view class="get_more" @tap.stop="bindToAnnouncement()">
							<text class="get_more_text">更多资讯</text>
							<image lazy-load class="get_more_icon" :src="imgPrefix('/static/image/icon/next.png')"></image>
						</view>
					</view>
					<view class="com_learning_scroll_view" :style="{ top: navTop }">
						<information-bar :list="languageList" :index="teacher.information.langeIndex" @bindTitleBar="getBarIndex"/>
					</view>
					<notice-list :list="teacher.noticeList" @bind-notice-view="bindLearning"/>
					<load-more v-if="teacher.noticeList.length==0" status="getmore" getmoreTitle="当前分类暂无数据"></load-more>
				</view>
				<!--可语资讯 end -->
				<zan-popup :show="showBalanceLow">
					<view :class="['popup','teacher',teacher.popupType==0?'perfect':'success']">
						<image lazy-load class="top_img p-a" :src="teacher.popupType==0?imgPrefix('/static/image/teacher/message1.png'):imgPrefix('/static/image/teacher/message.png')"></image>
						<view class="other_info p-a">
							<view class="title f_40 navy_blue t-c">{{teacher.popupType==0?'完善授课信息':'接单已开启'}}</view>
							<view class="msg f_28 gery1 t-c">{{teacher.popupType==0?'开启接单前，需先花1分钟完善授课信息，是否前往完善？':'请注意查看订单消息、课表消息、退款消息等…'}}</view>
							<view class="btn" @tap.stop="closeBalanceLowPopup(teacher.popupType==0?500:0),teacher.popupType==0?pageTo('/pages/teacher/teaching_information/index'):''">{{teacher.popupType==0?'完善信息':'我知道了'}}</view>
						</view>
						<image v-if="teacher.popupType==0" lazy-load @tap.stop="closeBalanceLowPopup" class="close_border_icon" :src="imgPrefix('/static/image/icon/close_border_icon.png')"></image>
					</view>
				</zan-popup>
			</block>
			<authorization @close="closeLoginPopup" @confirm="confirm" :showPopup="authorizationShow" :identity="userIdentity"></authorization>
	</view>
</template>
<script>
// 组件 satr
import courseList from '@/components/course-list/index.vue'; //课程列表
import noticeList from '@/components/notice-list/index.vue'; //资讯列表
import authorization from '@/components/authorization/index.vue'; //authorization
import informationBar from '@/components/information-bar/index.vue'; // 资讯标题栏
import zanPopup from '@/components/popup/index.vue';
import loadMore from '@/components/loadmore/index.vue';

// mixins satr
import { comPageMixinFun } from '@/static/mixins/comPageCommon.js';
import { commonMixinFun } from '@/static/mixins/common.js';
import { changeFormat } from '@/static/mixins/changeFormat.js';

// fun satr
import { getLocation } from '@/static/uitls/getLocation.js';
import { setCourseFormat } from '@/static/uitls/changeData.js';

import API from '@/static/api/index.js';
const statusBarHeight = uni.getSystemInfoSync().statusBarHeight;
const app = getApp();
let query = '';
export default {
	components: {
		courseList,
		noticeList,
		informationBar,
		zanPopup,
		loadMore,
		authorization
	},
	mixins: [commonMixinFun, comPageMixinFun, changeFormat],
	props:{
		currentIndex:{
			type:[String,Number],
			default:0
		}
	},
	data() {
		return {
			onHide:false,//当前组件是是否已经隐藏了
			authorizationShow:false,
			teacherState: 0, // 0未填写  1未开启  2 已开启
			navTop: '80px',
			user: {}, //用户信息
			latitude: app.globalData.location.lat,
			longitude: app.globalData.location.lng,
			city: app.globalData.location.city,
			recommend: app.globalData.location.address,
			hour_count: 0, //总课时
			showBalanceLow: false, //是否显示问卷popup  教师端的弹出
			languageTypeScrollPortion: 0,
			languageTypeScrollLeft: 0, //语种分类scroll值
			bannerIndex: 0,
			bannerList: [],
			languageList: [], // 通用的
			speakShareList: [],
			bindSpeakIndex: '',
			selectList: [],
			teacher:{
				info:{
					hour:0
				},
				information:{
					langeIndex:0
				},
				newNoticeList:[],//最新公告
				noticeList:[],//资讯列表
				popupType:0,//0为完善授课信息弹窗  1为接单已开启弹窗
			},
			unLoginBindType:'*'   // 记录未登录时点击了需要登录的操作，在登录成功后进行跳转操作 //*啥也没有  0 点击了小时  '-'开头的，'-'后面的是点击语种下标
		};
	},
	mounted() {
		this.navTop = Number(statusBarHeight + 44) + 'px';
	},
	watch: {
		languageList(val, oldVal) {
			
			if(this.userIdentity==0){
				this.$nextTick(function(){
					query.select('.language_scroll_view').boundingClientRect(rect => {
						app._log(9527,rect)
						let portion = 750/ uni.getSystemInfoSync().windowWidth;
						this.languageTypeScrollPortion =((84-48)*portion /(rect.width*portion - 750+96));
						this.$forceUpdate()
						app._log(this.languageTypeScrollPortion);
						// -750是屏幕宽度 
					}).exec();
				})
			}
		},
		pageRequestNum(val,oldVal){
			app._log(val,oldVal)
			this.setLoadingReverse(val>0)
		}
	},
	methods: {
		setHide(state){
			this.onHide=state;
			if(!state&&app.globalData.currentTab!=0){ // 显示index时和不是首页时开启
				if (this.userIdentity == 0) {
					this.getHourInfo();
				}else { // 教师
					this.getTeacherInfo()
				}
			}
		},
		closeLoginPopup(){
			this.authorizationShow=false;
			this.is_login = app.globalData.LOGION;
		},
		confirm(){
			this.showToComment();
			this.closeLoginPopup()
			let {unLoginBindType}=this;
			if(unLoginBindType!='*'){
				if(unLoginBindType==0){
					this.bindHourView()
				}else{
					this.bindClassification(unLoginBindType.replace('-',''))
				}
			}
			this.unLoginBindType=-1
			this.comShow()
		},
		// 通用方法 star
		comLoad(option) {
			app._log(this.userIdentity)
			app._log('comLoad接参', option);
			// 只执行一次的可以写在这里
			query = uni.createSelectorQuery().in(this);
			this.observe(app.globalData, 'location', this.watchLocation); // 开启监听
			uni.$on('loginSuccessCallBack',()=>{
				app._log('登录成功了')
				let pages = getCurrentPages();
				app._log(pages[pages.length-1].route)
				if(pages[pages.length-1].route=='pages/index/index'){ // 在底部栏页面进行登录的
					this.closeLoginPopup()
					this.setHide(false)
				}
				uni.$off('loginSuccessCallBack')
			});
			this.showToComment();
		},
		comShow() {
			this.watchLocation();
			// 每次显示的时候需要执行的写在这里
			if (Number(app.globalData.location.lat) == 0) {
				//没有定位过的才定位
				this._getLocation();
			}
			this.getIndexBannerList();
			if (this.userIdentity == 0) {
				// 学生
				this.getHourInfo();
				this.getIndexLangeList();
				this.getIndexArticleList();
				this.getIndexCourseList();
			} else {
				// 教师
				this.getTCateList()
				this.getTeacherInfo()
				this.getTIndexNotice()
			}
		},
		
		showToComment(){
			if(this.userIdentity == 0&&this.is_login){
				API.getToBeEvaluated().then(({code,data})=>{
					app._log(code,data)
					if(code==1&&data.course_order_id!=0){
						uni.showModal({
							content:'当前有待评价订单，\n是否前往评价？',
							success: (res) => {
								if(res.confirm){
									this.pageTo('/pages/comment/index', { course_order_id: data.course_order_id });
								}
							}
						})
					}
				})
			}
		},
		
		// 点击小时
		bindHourView(){
			let {userIdentity,is_login}=this;
			if(userIdentity==0&&!is_login){
				this.unLoginBindType = 0
				this.isLogin()
			}else{
				this.pageTo('/pages/course_record/index')
			}
		},
		getHourInfo() {
			app._log(this.is_login)
			if (this.is_login) {
				API.getMineInfo().then(res => {
					if (res.code == 1) {
						this.hour_count = res.data.hour_count;
						this.user = res.data.user;
						app.globalData.readingCount= res.data.reading_count;
						if(!this.onHide){
							setTimeout(()=>{
								this.getHourInfo()
							},5000)
						}
					}
				});
			} else {
				this.hour_count = 0;
			}
		},
		watchLocation() {
			let { lat, lng, city, address } = app.globalData.location;
			this.latitude = lat;
			this.longitude = lng;
			this.city = city;
			this.recommend = address;
			app._log('监听到定位信息变化', app.globalData.location);
		},
		// 轮播图列表
		getIndexBannerList() {
			let {userIdentity}=this;
			app._log(userIdentity)
			this.pageRequestNum+=1
			let send = userIdentity==0?API.getIndexBannerList():API.getTBannerList();
			send.then(res => {
				app._log(res);
				if (res.code == 1) {
					this.bannerList = res.data.banners;
				}
			}).finally(()=>{
				this.pageRequestNum-=1;
			})
		},
		// 语种分类列表
		getIndexLangeList() {
			this.pageRequestNum+=1
			API.getIndexLangeList().then(res => {
				app._log(res);
				if (res.code == 1) {
					this.languageList = res.data.languages;
				}
			}).finally(()=>{
				this.pageRequestNum-=1;
			});
		},
		// 文章列表
		getIndexArticleList() {
			this.pageRequestNum+=1
			API.getIndexArticleList().then(res => {
				// app._log('文章',res)
				if (res.code == 1) {
					this.speakShareList = res.data.article;
				}
			}).finally(()=>{
				this.pageRequestNum-=1;
			});
		},
		// 课程列表
		getIndexCourseList() {
			this.pageRequestNum+=1
			API.getIndexCourseList().then(({code,data}) => {
					// app._log('课程列表', res.data.teacher_couser);
					// app._log('课程列表', res);
					if (code == 1) {
						app._log(data.hasOwnProperty('teacher_couser')&&data.teacher_couser!=null?setCourseFormat(data.teacher_couser):[]);
						this.selectList =data.hasOwnProperty('teacher_couser')&&data.teacher_couser!=null?setCourseFormat(data.teacher_couser):[];
						app._log("selectList,,,,,",this.selectList)
					}
				}).finally(()=>{
				this.pageRequestNum-=1;
			});
		},

		languageTypeScroll(e) {
			//语种分类scroll事件
			app._log(e.detail.scrollLeft)
			this.languageTypeScrollLeft = e.detail.scrollLeft;
		},
		isLogin(){
			this.authorizationShow=true
		},
		// 通用方法 end
		// 点击语言view
		bindClassification(index) {
			if (this.is_login) {
				this.bindSpeakIndex = index;
				// this.showToast(`点了第${index + 1}种语言`);
				if (this.languageList[this.bindSpeakIndex].need_question_id > 0) {
					this.pageTo('/pages/search_from/index', { value: this.languageList[this.bindSpeakIndex].title }, '');
				} else {
					this.showBalanceLow = true;
				}
			} else {
				this.unLoginBindType = '-'+index
				this.closeBalanceLowPopup()
				this.authorizationShow=true
			}
		},

		// 获取用户位置信息
		_getLocation() {
			app._log('更新位置信息');
			// this.showLoading('加载中');
			let _this = this;
			getLocation(
				function(res) {
					let { code, latitude, longitude } = res;
					if (code) {
						_this.city = '北京';
						_this.recommend = '点击获取位置';
					} else {
						// app._log(latitude,longitude)
						_this.latitude = latitude;
						_this.longitude = longitude;
						API.reverseAddressResolution(latitude, longitude).then(function(resp) {
								app._log(789, app.globalData.location);
								// app._log(resp,999)
								try {
									let { formatted_addresses, address_component } = resp.result;
									app._log(formatted_addresses.recommend);
									_this.recommend = formatted_addresses.recommend; //格式化位置
									_this.city = address_component.city;
								} catch (err) {
									_this.city = '北京';
									_this.recommend = '点击获取位置';
								}
							})
							.catch(err => {
								_this.city = '北京';
								app._log(err);
								_this.recommend = '点击获取位置';
							});
					}
					app._log(res);
				},
				false,
				true,
				_this
			);
		},

		// 点击教师view
		toTeacherDetail(index) {
			this.pageTo('/pages/teacher_detail/index?id=' + this.selectList[index].teacher_course_id);
		},
		// 点击教师距离信息 跳转
		getLocationDetail(lat, lon, index) {
			app._log(lat, lon);
			if (lat != null && lon != null) {
				uni.openLocation({
					latitude: Number(lat),
					longitude: Number(lon),
					success: function() {
						app._log('success');
					},
					fail: err => {
						app._log(err);
						this.toTeacherDetail(index);
					}
				});
			} else {
				this.toTeacherDetail(index);
			}
		},
		// 关闭弹窗事件
		closeBalanceLowPopup(delay = 0) {
			setTimeout(() => {
				this.showBalanceLow = false;
			}, delay);
		},

		toQuestionnaire() {
			let { languageList, bindSpeakIndex } = this;
			this.showBalanceLow = false;
			this.pageTo('/pages/questionnaire/index', {
				color: languageList[bindSpeakIndex].icon_color,
				backgroundimage: languageList[bindSpeakIndex].backgroundimage,
				backgroundcolor: languageList[bindSpeakIndex].background_color,
				title: languageList[bindSpeakIndex].title,
				iconcolor:languageList[bindSpeakIndex].color,
				language_id: languageList[bindSpeakIndex].language_id
			});
		},
		// banner跳转
		toBannerRouter(index, url) {
			if (url != '') {
				this.pageTo(url);
			}
		},
		// banner滑动改变
		bannerSwiperChange(e) {
			let { current, source } = e.detail;
			app._log(source);
			if (source == 'touch'||source == 'autoplay') {
				this.bannerIndex = current;
			}
		},
		bindCurrentItem(e) {
			this.bannerIndex = e;
		},
		// 学生接口 end
		
		// ----------------------------------------------------
		
		// 教师接口 star
		getNoticeTitle(title,type){
			if(type==0){
				return title.split('】')[0].substring(1)||'通知'
			}else{
				return title.split('】')[1]
			}
		},
		// 点击开关接单
		bindOnline(){
			if(this.teacher.info.teacher_course==null){ //已填过课程信息
				this.teacher.popupType=0
				this.showBalanceLow=true
			}else{
				let {online}=this.teacher.info;
				let stateText = online==1?'关闭':'开启';
				uni.showModal({
					title:stateText+'提醒',
					content:`确认要${stateText}接单吗？`,
					confirmText:stateText+'接单',
					success:res=>{
						if(res.confirm){
							API.setTOnline().then(({code,msg})=>{
								if(code==1){
									this.teacher.info.online = online==1?0:1;
									this.$forceUpdate();
									if(this.teacher.info.online==1){
										this.showBalanceLow=true
										this.teacher.popupType=1
									}else{
										this.showToast('关闭成功')
									}
								}else{
									this.showToast(msg||(stateText+'失败'))
								}
							}).catch(err=>{
								this.showToast(err.msg||(stateText+'失败'))
							})
						}
					}
				})
				
			}
		},
		getTeacherInfo(){
			API.getTeacherInfo().then(res=>{
				if(res.code==1){
					this.teacher.info = res.data.teacher;
					app.globalData.readingCount= res.data.teacher.reading_count;
					app._log("----",this.teacher.info)
					uni.$emit('updateUserInfo',res);//用于更新消息待读数
					if(!this.onHide){
						setTimeout(()=>{
							this.getTeacherInfo()
						},5000)
					}
				}
			})
		},
		// 获取资讯标题
		getTCateList(){
			this.pageRequestNum+=1
			API.getTCateList().then(({code,data})=>{
				app._log(code,data)
				if(code==1){
					this.languageList = data.infoCate
					this.getTRecommendList(data.infoCate[this.teacher.information.langeIndex].info_cate_id)
				}else{
					this.languageList = []
				}
			}).catch(err=>{
				this.languageList = []
				app._log(err)
			}).finally(()=>{
				this.pageRequestNum-=1;
			})
		},
		// 切换资讯类型
		getBarIndex(index){
			app._log(index)
			this.teacher.information.langeIndex=index
			this.getTRecommendList(this.languageList[index].info_cate_id)
		},
		getTRecommendList(id){
			this.pageRequestNum+=1
			API.getTRecommendList(id).then(({code,msg,data})=>{
				if(code==1){
					this.teacher.noticeList = data.infomations
				}
			}).finally(()=>{
				this.pageRequestNum-=1;
			})
		},
		bindToAnnouncement(){
			this.pageTo('/pages/teacher/information_list/index',{index:this.teacher.information.langeIndex,list:JSON.stringify(this.languageList)})
		},
		getTIndexNotice(){
			this.pageRequestNum+=1
			API.getTIndexNotice().then(({code,data,msg})=>{
				app._log(code,data,msg)
				this.teacher.newNoticeList = code==1?data.notice:[];
			}).finally(()=>{
				this.pageRequestNum-=1;
			})
		},
		// 点击咨询
		bindLearning(index){
			app._log(index)
			let{languageList,teacher}=this;
			this.pageTo('/pages/teacher/article_details/index',{id:teacher.noticeList[index].infomation_id,index:teacher.information.langeIndex,list:JSON.stringify(languageList)})
		}
	}
};
</script>

<style lang="scss">
/* =============== 当前页公共样式 =============== */
::-webkit-scrollbar {
	width: 0;
	height: 0;
	color: transparent;
}
.content {
	background-color: #fff;
}


.margin_view {
	margin-left: 48rpx;
	margin-right: 48rpx;
}

.b32 {
	border-radius: 32rpx;
}

/* 标题通用样式 */
.module_top_title {
	display: flex;
	justify-content: space-between;
}

.module_title {
	font-size: 40rpx;
	line-height: 56rpx;
	color: #252748;
	position: relative;
	z-index: 1;
	width: 450rpx;
}

.module_title::before {
	position: absolute;
	left: 0rpx;
	top: 18rpx;
	line-height: 48rpx;
	font-size: 36rpx;
	color: #f3f4f9;
	z-index: -1;
	font-weight: bold;
}

/* =============== 头部 star =============== */
.header_view {
	width: 750rpx;
	height: 757rpx;
}
.header_bg_view{
	width: 750rpx;
	height: 680rpx;
	background-image: linear-gradient(0deg, #AA54FF 0%, #743BFF 100%);
	.header_wave{
		bottom: 0;left: 0;z-index: 14;mix-blend-mode: screen;height: 130rpx;width: 750rpx;
	}
}
.header_view .header_bg,
.header_view .header_item {
	width: 750rpx;
	height: 680rpx;
}
.header_bg {
	left: 0rpx;
	top: 0rpx;
}

.header_item {
	padding: 184rpx 48rpx 0rpx;
	z-index: 1;
}

.welcome_content {
	left: 48rpx;
	top: 0;
}

.welcome_top {
	margin-bottom: 8prx;
}

.welcome_logo {
	width: 48rpx;
	height: 48rpx;
	border-radius: 50%;
	border: solid 2rpx #ffffff;
	margin-right: 16rpx;
}

.user_name {
	font-size: 28rpx;
	line-height: 40rpx;
}

.welcome_bottom {
	line-height: 56rpx;
	margin-top: 8rpx;
}

.course_content{
	margin-bottom: 110rpx;
}

.course_title {
	line-height: 34rpx;
	opacity: 0.7;
	margin-bottom: 14rpx;
}

.course_num {
	font-size: 64rpx;
	line-height: 86rpx;
	padding-right: 8rpx;
}

.course_text {
	line-height: 32rpx;
}

/* =============== 地址和搜索 =============== */
.address_search {
	width: 654rpx;
	left: 48rpx;
	bottom: -70rpx;
}

.address_cion,
.search_icon {
	width: 48rpx;
	height: 48rpx;
	flex-shrink: 0;
}

.ctiy_name {
	line-height: 56rpx;
	color: #1f2633;
	padding: 0 16rpx;
	max-width: 288rpx;
}

.bottom_cion {
	width: 24rpx;
	height: 24rpx;
}

/* =============== 头部 end =============== */
/* =============== banner_swiper star =============== */
.banner_swiper {
	padding-top: 26rpx;
}

.banner_img {
	width: 576rpx !important;
	height: 280rpx !important;
}

.banner_img {
	transition: 0.2s;
	opacity: 1;
}

.banner_img.scale {
	opacity: 0.9;
	transform: scale(0.82);
}

.current_items {
	padding: 24rpx 48rpx 80rpx;
}

.current_item {
	width: 24rpx;
	height: 8rpx;
	border-radius: 4rpx;
	background-color: #dedfe6;
	margin-right: 8rpx;
	transition: 0.2s;
}
.current_item.active {
	background-color: #5c5d76;
}
/* =============== banner_swiper end =============== */

/* =============== 语种分类 star =============== */

.language_title {
	margin-bottom: 26rpx;
}

.language_text::before {
	content: 'language';
}
.scroll_icon {
	width: 84rpx;
	height: 6rpx;
	background-color: #eaeaea;
	right: 0rpx;
	bottom: -24rpx;
}
.scroll_icon_view {
	width: 48rpx;
	height: 6rpx;
	background-color: #9254ff;
	left: 0;
	top: 0;
}
.language_scroll {
	padding-top: 12rpx;
}
.language_scroll_view {
	display: inline-flex;
}

.language_img {
	width: 176rpx;
	height: 256rpx;
	border-radius: 40rpx 40rpx 8rpx 40rpx;
	box-shadow: 0px 8px 16px 0px rgba(182, 186, 248, 0.5);
}

.language_img:not(:last-child) {
	margin-right: 24rpx;
}

.language_img:nth-child(2n) {
	margin-top: 40rpx;
	margin-bottom: 96rpx;
}

/* =============== 语种分类 end =============== */
/* =============== 可语分享 star=============== */

.share_text::before {
	content: 'consulting';
}

.get_more {
	display: flex;
	align-items: center;
}

.get_more_text {
	font-size: 26rpx;
	color: #252748;
	margin-right: 4rpx;
}

.get_more_icon {
	width: 24rpx;
	height: 24rpx;
}

.speak_share_swiper_view {
	margin-top: 36rpx;
	height: 440rpx;
}

.speak_share_swiper_item {
	padding: 0 48rpx;
	box-sizing: border-box;
}

.speak_share_banner_img {
	width: 654rpx;
	height: 328rpx;
}

.share_content {
	margin-top: 16rpx;
}

.share_title {
	line-height: 40rpx;
}

.share_time {
	margin-top: 8rpx;
	line-height: 34rpx;
	color: #d1d2db;
}

/* =============== 可语分享 end=============== */

/* =============== 可语优选 star =============== */
.speak_select {
	margin-top: 96rpx;
}

.select_text::before {
	content: 'optimization';
}

.select_title_bottom {
	line-height: 34rpx;
	margin-bottom: 32rpx;
	margin-top: 4rpx;
}

.popup {
	text-align: center;
	position: relative;
}

.popup .search_img {
	width: 596rpx;
	height: 854rpx;
}

.popup .close_border_icon {
	margin-top: 56rpx;
	width: 80rpx;
	height: 80rpx;
}

.btn_view {
	width: 516rpx;
	height: 119rpx;
	left: 42rpx;
	top: 682rpx;
}
</style>

<style lang="scss">
.teaching_status {
	width: 654rpx;
	height: 370rpx;
	box-shadow: 0rpx 0rpx 32rpx 0rpx rgba(0, 0, 0, 0.05);
	border-radius: 24rpx;
	border: solid 2rpx #d7d7f7;
	padding: 16rpx 24rpx 24rpx;
	background-image: linear-gradient(0deg, #ffffff 25%, #efe5ff 100%);
	.view_top {
		.next_icon {
			width: 32rpx;
			height: 32rpx;
		}
	}
	.teaching_info {
		.info_view {
			display: flex;
			flex-direction: column;
			align-items: center;
			.to_write {
				.navy_blue{
					padding-bottom: 24rpx;
				}
				.image {
					width: 32rpx;
					height: 32rpx;
					vertical-align: middle;
				}
			}
			.navy_blue{
				line-height: 40rpx;
				&.f_40{
					padding-top: 12rpx;
				}
			}
		}
	}
	.btn {
		width: 606rpx;
		text-align: center;
		font-size: 32rpx;
		line-height: 92rpx;
		border-radius: 16rpx;
		&.close {
			color: #7f4aff;
			background-color: rgba(127, 74, 255, 0.05);
		}
		&.open {
			color: #ffffff;
			background-image: linear-gradient(270deg, #7f4aff 0%, #9254ff 100%);
		}
	}
}
.notice_view{
	width: 654rpx;
	height: 112rpx;
	background-color: #fcf7ff;
	border-radius: 8rpx;
	padding: 0 32rpx 0 16rpx;
	margin-top: 56rpx;
	.image{
		width: 112rpx;
		height: 112rpx;
	}
	.swiper_view{
		width: 494rpx;
		height: 84rpx;
		.swiper-item{
			margin-bottom: 4rpx;
		}
		.text{
			font-size: 26rpx;
			line-height: 36rpx;
		}
	}
}
.learning_information{
	margin-top: 64rpx;
	.learning_text::before {
		content: 'Welltalk News';
	}
	.module_top_title{
		padding-bottom: 60rpx;
	}
	.com_learning_scroll_view{
		/* #ifndef APP-PLUS-NVUE */
		position: -webkit-sticky;
		/* #endif */
		position: sticky;
		// top: var(--window-top);
		z-index: 10;
	}
}

.popup.teacher{
	width: 606rpx;
	border-radius: 24rpx;
	background-color: #fff;
	position: relative;
	padding:32rpx 44rpx;
	.top_img{
		width: 606rpx;
		height: 272rpx;
		left:0rpx;
	}
	&.perfect{
		height: 476rpx;
		.top_img{
			top: -128rpx;
		}
	}
	&.success{
		height: 434rpx;
		.top_img{
			top:-170rpx;
		}
	}
	.other_info{
		bottom:32rpx;
	.title{
		padding-bottom: 16rpx;
	}
	.msg{
		width: 518rpx;
	}
	.btn{
		margin: 32rpx auto 0;
		width: 478rpx;
		line-height: 92rpx;
		color: #fff;
		font-size: 32rpx;
		background-image: linear-gradient(270deg, #7f4aff 0%, #9254ff 100%);
		border-radius: 16rpx;
	}
	}
	.close_border_icon{
		position: absolute;
		bottom: -149rpx;
		left: 257rpx;
	}
}

</style>